﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DDit.Component.Tools.weixin
{
    public class SendTemplate
    {

        private static readonly string TextFormat = "<xml>" +
                    "<ToUserName><![CDATA[{0}]]></ToUserName>" +
                    "<FromUserName><![CDATA[{1}]]></FromUserName>" +
                    "<CreateTime>{2} </CreateTime>" +
                    "<MsgType><![CDATA[text]]></MsgType>" +
                    "<Content><![CDATA[{3}]]></Content>" +
                    "</xml>";

        private static readonly string ImageFormat = "<xml><ToUserName><![CDATA[toUser]]></ToUserName>" +
            "<FromUserName><![CDATA[fromUser]]></FromUserName>" +
            "<CreateTime>12345678</CreateTime>" +
            "<MsgType><![CDATA[image]]></MsgType>" +
            "<Image><MediaId><![CDATA[media_id]]></MediaId></Image></xml>";
        private static int CreateTime
        {
            get
            {
                return (int)(DateTime.Now - new DateTime(1970, 1, 1)).TotalSeconds;
            }
        }
        public static string SendText(string toUser, string fromUser, string msg)
        {
            return string.Format(TextFormat, toUser, fromUser, CreateTime, msg);
        }
    }
}
